package com.itheima.dubbo.mysql.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.itheima.commons.pojo.entity.Admin;
import com.itheima.dubbo.interfaces.AdminApi;
import com.itheima.dubbo.mysql.mapper.AdminMapper;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

@Service
public class AdminApiImpl implements AdminApi {
    @Autowired
   private AdminMapper adminMapper;

    @Override
    public String checkPassword(String username) {
        List<Admin> admins = adminMapper.selectList(Wrappers.lambdaQuery(Admin.class)
                .eq(Admin::getUsername, username));
        //获得密码
        String password=null;
        for (Admin admin : admins) {
             password = admin.getPassword();
            System.out.println(password);
        }
        return password;
    }

    @Override
    public Admin getAdmin(String username) {
        Admin admin = adminMapper.selectOne(Wrappers.lambdaQuery(Admin.class)
                .eq(Admin::getUsername, username));
        return admin;
    }

    @Override
    public Admin getAdminByAid(Long adminId) {
        return adminMapper.selectById(adminId);
    }
}
